package cn.edu.cjw.APMFP.ui.table;

import cn.edu.cjw.APMFP.ProductionTask.pojo.ProductionTask;
import cn.edu.cjw.APMFP.Util.DateUtil;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class ProductionTaskTableModel extends AbstractTableModel{

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private List<ProductionTask> list;
    private String[] columns = { "任务编号", "创建人账号", "负责人账号", "状态", "完成日期", "备注" };

	public ProductionTaskTableModel(List<ProductionTask> list) {
		super();
		this.list = list;
	}

	@Override
	public int getRowCount() {
		return list.size();
	}

	@Override
	public int getColumnCount() {
		return columns.length;
	}
	
	@Override
	public String getColumnName(int column) {
		return columns[column];
	}
	
	private Object getColumn(ProductionTask entity, int n) {
        switch (n) {
            case 0: return entity.getTaskId();
            case 1: return entity.getFounder();
            case 2: return entity.getChargeMan();
            case 3: return Boolean.TRUE.equals(entity.getExamine()) ? "已完成" : "未完成";
            case 4: return DateUtil.format(entity.getCompletionTime(), DateUtil.DATE_TIME);
			case 5: return entity.getDescribe();
            default: return null;
        }
    }

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return getColumn(list.get(rowIndex), columnIndex);
	}

}
